package com.gitee.zhangchenyan.takin.auth;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Deacription
 * @Author zl
 * @Date 2021/12/7 21:19
 * @Version 1.0
 *
 * 不继承WebMvcConfigurationSupport,改为实现WebMvcConfigurer接口 原先配置的时间格式LocalDateTimeFormatConfig失效
 **/
@Configuration
public class AuthWebMvcConfiguration implements WebMvcConfigurer {

    //在此处，将拦截器注册为一个 Bean;为何需要bean因为HandlerInterceptorAdapter优先级太高
    @Bean
    public AuthCheckLoginHandlerInterceptor loginInterceptor() {
        return new AuthCheckLoginHandlerInterceptor();
    }
    //在此处，将拦截器注册为一个 Bean;为何需要bean因为HandlerInterceptorAdapter优先级太高
    @Bean
    public AuthCheckPermissionHandlerInterceptor permissionInterceptor() {
        return new AuthCheckPermissionHandlerInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor()).addPathPatterns("/**");
        registry.addInterceptor(permissionInterceptor()).addPathPatterns("/**");
    }
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

}
